﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using HP.Cachalote.DataModels;
using HP.Cachalote.Services.Validations;

namespace HP.Cachalote.WPF.ValidationRules
{
    public class TodoLabelNameValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            var todoLabelValidator = new TodoLabelValidator();

            var label = new TodoLabel
            {
                Name = value.ToString().Trim()
            };

            if (!todoLabelValidator.CheckRequiredName(label))
            {
                return new ValidationResult(false, todoLabelValidator.GetError(TodoLabelValidator.NameErrorKey));
            }
            else if (!todoLabelValidator.CheckNameLength(label))
            {
                return new ValidationResult(false, todoLabelValidator.GetError(TodoLabelValidator.NameErrorKey));
            }

            return new ValidationResult(true, null);
        }
    }
}
